<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<button type="default" @click="onWBtn()">写入日期</button>
			<button type="default" @click="onRBtn()">读取日期</button>
			<text>{{date}}</text>
		</view>
	</view>
</template>

<script>
	import {dayjs} from '@/uni_modules/iRainna-dayjs/js_sdk/dayjs.min.js'
	import FileJS from "@/utils/File.js";
	export default {
		data() {
			return {
				title: 'Hello',
				date: '',
			}
		},
		onLoad() {

		},
		methods: {
			async writeFile(value) {
				// 获取文件路径
				const filePath = FileJS.root() + "/device.txt";
				// 获取要写入的内容
				const content = value;
				console.log('file path', filePath)
				// 写入文件
				const result = await FileJS.writeTxt(filePath, content);
				// 如果写入成功
				if (result) {
					console.log("文件写入成功");
				} else {
					console.error("文件写入失败");
				}
			},
			async readFile() {
				// 获取文件路径
				const filePath = FileJS.root() + "/device.txt";
				// 读取文件内容
				const content = await FileJS.readTxt(filePath);
				const that = this;
				// 如果读取到内容
				if (content) {
					console.log('2334', content)
					//处理读取到文本内容之后的逻辑
					this.date = content;
				} else {
					//处理读取不到的逻辑
					console.error('读取错误', content)
				}
			},
			onWBtn() {
				const date = dayjs().format('YYYY-MM-DD HH:mm:ss');
				console.log('11111', date)
				plus.storage.setItem('date', date);
			},
			onRBtn() {
				console.log('22333')
				this.date = plus.storage.getItem('date')
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>